package com.usian.admin.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.admin.mapper.TbAdminMapper;
import com.usian.admin.mapper.TbAdminMapper;
import com.usian.admin.service.TbAdminService;


import com.usian.model.base.BaseServiceImpl;
import com.usian.model.common.dtos.PageResponseResult;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.zuoye.taadmin01.TbAdmin;
import com.usian.model.zuoye.taadmin01.TbAdminDto;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TbAdminServiceImpl extends BaseServiceImpl<TbAdminMapper, TbAdmin> implements TbAdminService {
    @Autowired
    TbAdminMapper tbAdminMapper;

    @Override
    public List<TbAdmin> findAll(String name) {
        if (name==null){
            return tbAdminMapper.selectList(null);
        }
        QueryWrapper<TbAdmin> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(true,"realname",name);
        List<TbAdmin> adminList = tbAdminMapper.selectList(queryWrapper);
        for (TbAdmin tbAdmin : adminList) {
            System.out.println(tbAdmin);
        }
        return adminList;
    }

    @Override
    public void update(String realname,Integer id){
        tbAdminMapper.edit(realname,id);
    }


    @Override
    public TbAdmin findById(Integer id){
        return  tbAdminMapper.findById(id);
    }

    @Override
    public void findById(String name, Integer id,Integer state) {
        if (name!=null){
            TbAdmin admin=new TbAdmin();
            admin.setId(id);
            admin.setRealname(name);
            tbAdminMapper.updateById(admin);
        }else {
            if (state==0){
                TbAdmin admin = new TbAdmin();
                admin.setId(id);
                admin.setUserstate(1);
                tbAdminMapper.updateById(admin);
            }else {
                TbAdmin admin = new TbAdmin();
                admin.setId(id);
                admin.setUserstate(0);
                tbAdminMapper.updateById(admin);
            }
        }



    }

}